
<template>
  <div>
    <van-nav-bar title="回复问题" left-arrow @click-left="back" />
    <van-cell-group v-if="questionData">
      <van-cell title="问题名称" :value="questionData.name" />
      <van-cell title="问题详情" :value="questionData.details" />
      <van-cell title="回答数量" :value="questionData.count" />
      <van-cell title="用户名称" :value="questionData.username" />
      <van-cell title="回答的内容" :value="questionData.content" />
      <van-cell title="回答时间" :value="questionData.ctime" />
    </van-cell-group>
  </div>
  <div>
    <van-field
        v-model="inputValue"
        placeholder="请输入回答"
        style="margin: 20px"
    ></van-field>

    <van-button type="primary" icon="search" style="margin-right: 10px;" @click="answers">回答</van-button>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import axios from "axios";
import { useRouter } from "vue-router";

const router = useRouter();
const questionId = ref(null);
const questionData = ref(null);

onMounted(() => {
  fetchQuestionData();
});

const fetchQuestionData = () => {
  questionId.value = router.currentRoute.value.query.id;
  axios.get("question/queryById?id=" + questionId.value).then((res) => {
    if (res.data.code === 0) {
      questionData.value = res.data.data;
    }
  });
}

const back = () => {
  history.back();
}
</script>

<style scoped>
/* 样式 */
</style>
